<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    String static_path = path + "/static/alpha";
%>

<div class="card card-primary card-outline">
    <div class="card-header">
        <h3 class="card-title">禁用列表</h3>

    </div>
    <!-- /.card-header -->
    <div class="card-body p-0">
        <div class="mailbox-controls">
            <!-- Check all button -->
            <button type="button" class="btn btn-default btn-sm checkbox-toggle" ><i class="fa fa-square-o"></i>
            </button>
            <div class="btn-group">
                <%--<button type="button" class="btn btn-default btn-sm" id="deleteChecked"><i class="fa fa-trash-o"></i></button>--%>
                <button type="button" class="btn btn-default btn-sm" id="disableList"><i class="fa fa-reply"></i></button>
                <%--<button type="button" class="btn btn-default btn-sm"><i class="fa fa-share"></i></button>--%>
            </div>
            <!-- /.btn-group -->
            <button type="button" onclick="location.reload();" class="btn btn-default btn-sm"><i class="fa fa-refresh"></i></button>
            <!-- /.float-right -->
        </div>
        <div class="table-responsive mailbox-messages">
            <table class="table table-hover table-striped">
                <br>
                <b style="margin-left: 20px">一级菜单</b>
                <tbody>
                <tr>
                    <td></td>
                    <td class="mailbox-name" ><b>ID</b></td>
                    <td class="mailbox-name" ><b>菜单名</b></td>
                    <td class="mailbox-attachment"><b>Url</b></td>
                    <td class="mailbox-attachment"><b>排序</b></td>
                    <td class="mailbox-date"><b>恢复</b></td>
                </tr>
                <c:forEach items="${requestScope.disabledList}" var="mn">
                    <c:if test="${mn.parentId eq 0}">
                        <tr>
                            <td><input type="checkbox" id="ck" value="${mn.id} "></td>
                                <%--<td class="mailbox-star"><a href="#"><i class="fa fa-star text-warning"></i></a></td>--%>
                            <td class="mailbox-name" >${mn.id} </td>
                            <td class="mailbox-name" ><b id="updataName">${mn.name} </b></td>

                            <td class="mailbox-subject"><a id="updataUrl">${empty mn.url ? 'null':mn.url}</a></td>
                            <td class="mailbox-attachment"><a id="updataSort">${mn.sort}</a></td>
                            <td class="mailbox-date"  ><button class="disable">恢复</button></td>
                        </tr>
                    </c:if>
                </c:forEach>
                </tbody>
            </table>
            <hr>
            <%--<br>--%>
            <b style="margin-left: 20px">二级菜单</b>
            <table class="table table-hover table-striped">
                <tbody>
                <tr>
                    <td></td>
                    <td class="mailbox-name" ><b>ID</b></td>
                    <td class="mailbox-name" ><b>菜单名</b></td>
                    <td class="mailbox-attachment"><b>Url</b></td>
                    <td class="mailbox-attachment"><b>排序</b></td>
                    <td class="mailbox-date"><b>恢复</b></td>
                </tr>
                <c:forEach items="${requestScope.disabledList}" var="mn">
                    <c:if test="${mn.parentId != 0}">
                        <tr>
                            <td><input type="checkbox" value="${mn.id} " id="ck"></td>
                                <%--<td class="mailbox-star"><a href="#"><i class="fa fa-star text-warning"></i></a></td>--%>
                            <td class="mailbox-name" >${mn.id} </td>
                            <td class="mailbox-name" ><b>${mn.name} </b></td>

                            <td class="mailbox-subject"><a>${empty mn.url ? 'null':mn.url}</a></td>
                            <td class="mailbox-attachment"><a>${mn.sort}</a></td>
                            <td class="mailbox-date"  ><button class="disable">恢复</button></td>
                        </tr>
                    </c:if>
                </c:forEach>
                </tbody>
            </table>
            <!-- /.table -->
        </div>
        <!-- /.mail-box-messages -->
    </div>
    <!-- /.card-body -->
    <div class="card-footer p-0">
        <div class="mailbox-controls">
            <div></div>
        </div>
    </div>
</div>

<script>

    $("#disableList").click(function(){
        //获得选中的复选框对应的carid
        var ckx = $("input[id=ck]:checked");
        //ckx是集合  中间存放的是选中的复选框
        var ids ="";
        ckx.each(function(){
            //$(this)//表示的是集合中间的一个元素  $(this)是一个选中的复选框
            /*var t = $(this).parent().next().html();*/
            var t = $(this).val();
            ids=ids+","+t;
        });
        var mymessage=confirm("确定恢复选中项吗？");
        if(mymessage==true) {
            $.ajax({
                url:"<%=path%>/manage/memu_settings/update_bigType/disable_list_all",
                type:"get",
                data:{
                    ids : ids,
                },
                async:false,
                success:function(mes){
                }
            });
            ckx.each(function(){
                $(this).parent().parent().parent().remove();
            });
        }
        if(mymessage==false){
            alert("已取消")
        }
    })

    //单一恢复
    $(".disable").click(function(){
            var id=$(this).parent().prev().prev().prev().prev().html();
            var name=$(this).parent().prev().prev().prev().children().html();
            var mymessage=confirm("确定恢复"+"“"+name+"“"+"吗？");
            if(mymessage==true) {
                $.ajax({
                    url:"<%=path%>/manage/memu_settings/update_bigType/disable_list",
                    type:"get",
                    data:{
                        id : id,
                    },
                    async:false,
                    success:function(mes){
                    }
                });
                $(this).parent().parent().remove();
            }
            if(mymessage==false){
                alert("已取消")
            }
        })
</script>

<script>
    $(function () {
        //Enable iCheck plugin for checkboxes
        //iCheck for checkbox and radio inputs
        $('.mailbox-messages input[type="checkbox"]').iCheck({
            checkboxClass: 'icheckbox_flat-blue',
            radioClass   : 'iradio_flat-blue'
        })

        //Enable check and uncheck all functionality
        $('.checkbox-toggle').click(function () {
            var clicks = $(this).data('clicks')
            if (clicks) {
                //Uncheck all checkboxes
                $('.mailbox-messages input[type=\'checkbox\']').iCheck('uncheck')
                $('.fa', this).removeClass('fa-check-square-o').addClass('fa-square-o')
            } else {
                //Check all checkboxes
                $('.mailbox-messages input[type=\'checkbox\']').iCheck('check')
                $('.fa', this).removeClass('fa-square-o').addClass('fa-check-square-o')
            }
            $(this).data('clicks', !clicks)
        })

        //Handle starring for glyphicon and font awesome
        $('.mailbox-star').click(function (e) {
            e.preventDefault()
            //detect type
            var $this = $(this).find('a > i')
            var glyph = $this.hasClass('glyphicon')
            var fa    = $this.hasClass('fa')

            //Switch states
            if (glyph) {
                $this.toggleClass('glyphicon-star')
                $this.toggleClass('glyphicon-star-empty')
            }

            if (fa) {
                $this.toggleClass('fa-star')
                $this.toggleClass('fa-star-o')
            }
        })
    })
</script>